<template>
  <div>
    <a-form :form="form" style="max-width: 500px; margin: 40px auto 0;">
      <a-alert
        :closable="true"
        message="请选择微信或支付宝支付。"
        style="margin-bottom: 24px;"
      />
      <a-form-item
        label="付款账户"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        class="stepFormText"
      >
        <a-button icon="wechat" @click="wechat">微信</a-button>
        <a-button icon="alipay-circle" style="margin-left: 30px" @click="alipay">支付宝</a-button>
      </a-form-item>
      <a-form-item :wrapperCol="{span: 19, offset: 5}">
        <a-button :loading="loading" type="primary" @click="nextStep">完成支付</a-button>
        <a-button style="margin-left: 8px" @click="prevStep">上一步</a-button>
      </a-form-item>
    </a-form>
  </div>
</template>

<script>
export default {
  name: 'Step2',
  data () {
    return {
      labelCol: { lg: { span: 5 }, sm: { span: 5 } },
      wrapperCol: { lg: { span: 19 }, sm: { span: 19 } },
      form: this.$form.createForm(this),
      loading: false,
      timer: 0
    }
  },
  methods: {
    nextStep () {
      const { form: { validateFields } } = this
      this.loading = true
      validateFields((err, values) => {
        if (!err) {
          const hide = this.$message.loading('正在查询支付状态', 0)
          setTimeout(() => {
            hide()
            this.$message.success('已完成支付')
            this.loading = false
            this.$emit('nextStep')
          }, 1000)
        } else {
          this.loading = false
        }
      })
    },
    prevStep () {
      this.$emit('prevStep')
    },
    wechat () {
      window.open('http://alipay.topkoon.com/Wx/ScanCode/index.asp')
    },
    alipay () {
      window.open('http://alipay.topkoon.com/Ali/alipay/page.pay.asp')
    }
  }
}
</script>

<style lang="less" scoped>
  .stepFormText {
    margin-bottom: 24px;

    .ant-form-item-label,
    .ant-form-item-control {
      line-height: 22px;
    }
  }

</style>
